/**
 * timestampMarker - factory
 * 封装一个拦截器服务，用以实现loading效果
 */
class timestampMarker{
    constructor($rootScope, $timeout) {
        this.$rootScope = $timeout;
        this.$timeout   = $timeout;

        const timestampMarker = {
            request: (config) => {
                if (config.url.indexOf('checklogin')==-1&&config.url.indexOf('latest')==-1&&config.url.indexOf('lists')==-1&&config.url.indexOf('trace/search')==-1&&config.url.indexOf('teamlist')==-1&&config.url.indexOf('registerfield/add')==-1&&config.url.indexOf('registerfield/del')==-1&&config.url.indexOf('registerfield/update')==-1&&config.url.indexOf('getrelated')==-1&&config.url.indexOf('material/unbindall')==-1) {
                    $rootScope.loading = true;
                    angular.element('body').removeClass('check-login')
                } else {
                    $rootScope.loading = false;
                    angular.element('body').addClass('check-login')
                }
                config.requestTimestamp = new Date().getTime();
                return config;
            },
            response: (response) => {
                $rootScope.loading = false;
                response.config.responseTimestamp = new Date().getTime();
                return response;
            }
        };

        return timestampMarker;
    }
}

timestampMarker.$inject = ['$rootScope', '$timeout'];

export default timestampMarker;